package action;

import grammer.StartEndTime;
import grammer.Type1TimeObject;
import grammer.components.PredicateEnum;
import grammer.phrase.Phrase;
import timer.Timer;
import action.concreteActions.ChangeWeatherAction;
import action.concreteActions.CompoundUseAction;
import action.concreteActions.GoToAction;
import action.concreteActions.SimpleUseAction;
import action.concreteActions.TerminalAction;

/**
 * 
 * @author Minodor
 * 
 *         Builds an Action from a tokenized scenario line
 * 
 */
public class ActionBuilder {

	public void createAction(Phrase p, int type) {
		ActionSInterface newAction;
		if (type == 10) {
			newAction = new ChangeWeatherAction(Timer
					.getTimer(((Type1TimeObject) p.getTime()).getTime1()), p
					.getWeather());
			newAction.setOwner("Weather");
			ActionPool.add(newAction);
		} else {
			switch (type) {
			case 1: {
				newAction = Class1Actionfactory.selectAction(Timer
						.getTimer(((Type1TimeObject) p.getTime()).getTime1()),
						p.getPredicate());
				newAction.setOwner(p.getSubject().getName());
				ActionPool.add(newAction);
				break;
			}
			case 2: {
				newAction = new CompoundUseAction(Timer
						.getTimer(((StartEndTime) p.getTime()).getStartTime()),
						Timer.getTimer(((StartEndTime) p.getTime())
								.getEndTime()), p.getPredicate());
				newAction.setOwner(p.getSubject().getName());
				ActionPool.add(newAction);
				break;
			}
			case 3: {
				newAction = new CompoundUseAction(Timer
						.getTimer(((StartEndTime) p.getTime()).getStartTime()),
						Timer.getTimer(((StartEndTime) p.getTime())
								.getEndTime()), p.getPredicate(), p
								.getDirectObject());
				newAction.setOwner(p.getSubject().getName());
				ActionPool.add(newAction);
				break;
			}
			case 4: {
				newAction = new SimpleUseAction(Timer
						.getTimer(((Type1TimeObject) p.getTime()).getTime1()),
						p.getPredicate(), p.getDirectObject());
				newAction.setOwner(p.getSubject().getName());
				ActionPool.add(newAction);
				break;
			}
			case 5: {
				newAction = new SimpleUseAction(Timer
						.getTimer(((Type1TimeObject) p.getTime()).getTime1()),
						p.getPredicate(), p.getDirectObject(), p
								.getModalObject());
				newAction.setOwner(p.getSubject().getName());
				ActionPool.add(newAction);
				break;
			}
			case 7: {
				if (p.getPredicate().getPredicate().equals(
						PredicateEnum.WAKES_UP_IN)) {
					newAction = new TerminalAction(Timer
							.getTimer(((Type1TimeObject) p.getTime())
									.getTime1()), p.getPredicate(), p
							.getLocalObject());
					newAction.setOwner(p.getSubject().getName());
					ActionPool.add(newAction);
				} else {
					newAction = new GoToAction(Timer
							.getTimer(((Type1TimeObject) p.getTime())
									.getTime1()), p.getLocalObject());
					newAction.setOwner(p.getSubject().getName());
					ActionPool.add(newAction);
				}
				break;
			}
			}

		}

	}

}
